package android.longs.study.mytest.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import android.longs.study.mytest.model.CommonUserSubjectModel;
import android.longs.study.utils.H3Utils;

public class CommonSubDaoImple implements CommonSubDao {

    /**
     * 添加测试题 
     */
    @Override
    public void addTestModel(CommonUserSubjectModel model) {
	Session currentSession = H3Utils.getCurrentSession();
	currentSession.save(model);
    }

    /**
     * 查询所有
     */
    @Override
    public List<CommonUserSubjectModel> queryAllTestModels() {
	Session currentSession = H3Utils.getCurrentSession();
	//hql
	String hql = "from CommonUserSubjectModel";
	//query
	Query createQuery = currentSession.createQuery(hql);
	//list
	List<CommonUserSubjectModel> list = createQuery.list();
	return list;
    }

    @Override
    public List<CommonUserSubjectModel> queryAllTestModels(int start) {
	Session currentSession = H3Utils.getCurrentSession();
	//hql
	String hql = "from CommonUserSubjectModel";
	//query
	Query createQuery = currentSession.createQuery(hql).setFirstResult(start).setMaxResults(15);
	//list
	List<CommonUserSubjectModel> list = createQuery.list();
	return list;
    }

    @Override
    public CommonUserSubjectModel queryModelFormUid(String uid) {
	Session session = H3Utils.getCurrentSession();
	//创建 hql
	CommonUserSubjectModel customer =(CommonUserSubjectModel) session.createQuery("from CommonUserSubjectModel c where c.uid = "+uid).uniqueResult();
	return customer;
    }

    @Override
    public CommonUserSubjectModel queryModelFormId(String id) {
	Session session = H3Utils.getCurrentSession();
	//创建 hql
	CommonUserSubjectModel customer =(CommonUserSubjectModel) session.createQuery("from CommonUserSubjectModel c where c.id = "+id).uniqueResult();
	return customer;
    }

   

    @Override
    public void updateTestModel(CommonUserSubjectModel model) {
	Session currentSession = H3Utils.getCurrentSession();
	currentSession.saveOrUpdate(model);
    }

}
